import { request } from '@/utils';

/**
 * 微信身份验证
 * @param {*} data
 * code
 * type
 */
export function wxLogin(data) {
  return request({
    url: '/h5/getAuthUser',
    method: 'post-x-www-form-urlencoded',
    data: data,
    showLoading: false,
  });
}

/**
 * 获取企业agentId
 * @param {*} params
 */
export function queryAgentIdByCorpId(corpId) {
  return request({
    url: '/h5/queryAgentIdByCorpId',
    method: 'get',
    data: {
      corpId,
    },
  });
}

/**
 * 获取 wx.config 注入的签名信息: timestamp、nonceStr、signature
 * @param {*} url
 */
export function getCompanySign(url) {
  // const isDeploy = /deploy/.test(location.pathname);
  // const data = {
  //   url,
  // };
  // if (isDeploy) {
  //   data.corpId = 'JSAPI';
  // }
  return request({
    url: '/h5/getCompanySign',
    method: 'post-x-www-form-urlencoded',
    data: {
      url,
    },
  });
}

/**
 * 获取 wx.agentConfig 注入的签名信息: timestamp、nonceStr、signature
 * @param {*} url
 */
export function getAppSign(url) {
  return request({
    url: '/h5/getAppSign',
    method: 'post-x-www-form-urlencoded',
    data: { url },
  });
}
/**
 * 获取微信公众号 wx.config 注入的签名信息: timestamp、nonceStr、signature
 * @param {*} url
 */
export function getJsapiSign(url) {
  return request({
    url: '/h5/getJsapiSign',
    method: 'post',
    data: { url },
  });
}
/**
 * 获取分享授权回调地址
 * @param {*} data
 */
export function getWxShareAuthRedirectUri(data) {
  return request({
    url: '/h5/getWxShareAuthRedirectUri',
    method: 'get',
    data,
  });
}
/**
 * 获取企业应用相关信息
 * @param {*} businessId
 */
export function queryBusinessAppId(businessId) {
  return request({
    url: `/h5/queryBuinessAppId?businessId=${businessId}`,
    method: 'get',
    showLoading: false,
  });
}
